"""
file: test_clock.py
Author: 城下秋草
Date: 2024/12/6
Desc: 时钟处理
"""
import time

from playwright.sync_api import sync_playwright, expect

playwright = sync_playwright().start()
browser = playwright.chromium.launch(
    headless=False,
    slow_mo=500,
    args=["--window-position=1024,-850"]
)
page = browser.new_page()

page.clock.install(time="2024-10-10 10:10:10")
# page.goto("file:///C:/dev/qiucao/PlayWrightCourse/test.html")
# time.sleep(3)
#
# page.clock.pause_at("2024-10-10 10:10:15")
# time.sleep(3)
# page.clock.resume()
# time.sleep(3)
# page.clock.run_for(30000)
# time.sleep(2)
page.goto("https://demoqa.com")
page.wait_for_load_state(state="domcontentloaded")

page.get_by_role("heading",level=5,name="Elements").click()
page.get_by_text("Dynamic Properties").click()
page.clock.fast_forward(5000)
btn1 = page.locator("button#visibleAfter")
btn1.wait_for(state="visible")
btn1.click(timeout=2000)
print("click visble done!")

page.reload()
btn2 = page.locator("#enableAfter")
page.clock.fast_forward(5000)
expect(btn2).not_to_have_attribute(name="disabled",value="")
btn2.click(timeout=1000)
print("click enable done!")

page.reload()
btn3 = page.locator("#colorChange")
page.wait_for_function("() => document.querySelector('#colorChange').classList.contains('text-danger')")
print("color changed!")